<?php
namespace addons\paotui\library\GatewayWorker\Applications\Paotui\controller;

use \Workerman\Worker;
use \GatewayWorker\BusinessWorker;

class Sbusinessworker
{
    public function __construct()
    {
        if (\PHP_SAPI !== 'cli') {
            exit("Only run in command line mode \n");
        }

        require_once __DIR__ . '/../../../vendor/autoload.php';

        $config = get_addon_config('paotui');
        // bussinessWorker 进程
        $worker = new BusinessWorker();
        // worker名称
        $worker->name = 'PaotuiBusinessWorker';
        // bussinessWorker进程数量
        $worker->count = $config['worker_process_number'];
        // 服务注册地址
        $worker->registerAddress = '127.0.0.1:'.$config['register_port'];
        $worker->eventHandler = 'addons\paotui\library\GatewayWorker\Applications\Paotui\Events';
        // 如果不是在根目录启动，则运行runAll方法
        if (!defined('GLOBAL_START')) {
            Worker::runAll();
        }
    }
}
